package fun.codedesign.yinxue.code.php2java.service;

import fun.codedesign.yinxue.code.engine.antlr.java.Java20Lexer;
import fun.codedesign.yinxue.code.engine.antlr.java.Java20Parser;
import fun.codedesign.yinxue.code.engine.antlr.java.JavaParserLisnter;
import fun.codedesign.yinxue.util.ResourceUtil;
import org.antlr.v4.runtime.ANTLRInputStream;
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.tree.ParseTree;
import org.antlr.v4.runtime.tree.ParseTreeWalker;

public class JavaAntlrChecker {
    public static void main(String[] args) throws Exception {
        test1();
    }

    static void test1() throws Exception {
        CharStream input = new ANTLRInputStream(ResourceUtil.getResourceAsInputStream("Php2Java.java"));
        Java20Lexer lexer = new Java20Lexer(input);
        CommonTokenStream tokens = new CommonTokenStream(lexer);
        Java20Parser parser = new Java20Parser(tokens);
        ParseTree tree = parser.start_();
        ParseTreeWalker walker = new ParseTreeWalker();
        walker.walk(new JavaParserLisnter(), tree);
    }

    public static void check(String javaText) {
        CharStream input = new ANTLRInputStream(javaText);
        Java20Lexer lexer = new Java20Lexer(input);
        CommonTokenStream tokens = new CommonTokenStream(lexer);
        Java20Parser parser = new Java20Parser(tokens);
        ParseTree tree = parser.start_();
        ParseTreeWalker walker = new ParseTreeWalker();
        walker.walk(new JavaParserLisnter(), tree);
    }
}
